Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experiments): Add saved metrics #25867

Merged
merged 7 commits into from
Oct 31, 2024
Merged

feat(experiments): Add saved metrics #25867

merged 7 commits into from
Oct 31, 2024

Conversation

neilkakkar
Copy link
Contributor

@neilkakkar neilkakkar commented Oct 29, 2024

Problem

Add saved metrics backend, allow adding metadata like metric type to the relation.

TODO: Split this into two PRs, one for models, one for adding model to experiment, otherwise we'll bork things like with holdouts migration.

TODO: Add moar tests for experiments handling of saved metrics, and update flow.

Changes

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@neilkakkar neilkakkar marked this pull request as ready for review October 30, 2024 12:17
{
"name": "Test Experiment saved metric",
"description": "Test description",
"query": {"events": [{"id": "$pageview"}]},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only accept ExperimentTrendsQuery | ExperimentFunnelsQuery

(fine to do the validation in a follow up, but maybe better to pass the correct query now to avoid having to update this later)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see! How do you generally validate this? I could just check the kind in the json, anything else I can do with hogql?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not important in this test will do it in a follow up 👍 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would something like this work?

if value["kind"] === "ExperimentTrendsQuery":
	ExperimentTrendsQuery(**value)
elif value["kind"] === "ExperimentFunnelsQuery":
	ExperimentFunnelsQuery(**value)
else:
	raise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see we have pydantic generated schema, should be able to validate that, will do that 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metrics need similar validation right? Not sure where this is happening right now, don't see it in the viewset / serializer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that would be great!

actually, do we validate filters at all? I don't see it in the serializer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah a little bit, shouldn't have properties and should exist is the only validation.

Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@neilkakkar neilkakkar merged commit 81d3ffb into master Oct 31, 2024
89 checks passed
@neilkakkar neilkakkar deleted the saved_metrics branch October 31, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants